import 'package:flutter/cupertino.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/common/xindong_define.dart';
import 'package:xindong/utils/xindong_text_util.dart';

class XinDongCommonSwitchItem extends StatelessWidget {
  final String title;
  final String? desc;
  final bool value;
  final Function(bool)? onChanged;

  const XinDongCommonSwitchItem({super.key, required this.title, this.desc, required this.value, this.onChanged});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: kCellHeight,
      color: DZColors.cellColor,
      padding: const EdgeInsets.only(left: kPaddingValue, right: kPaddingValue),
      margin: const EdgeInsets.only(bottom: 1),
      child: Row(
        children: [
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  title,
                  style: const TextStyle(fontSize: 15, color: DZColors.titleColor, height: 1.2),
                ),
                if (!TextUtil.isEmpty(desc))
                  Text(
                    desc!,
                    style: const TextStyle(fontSize: 12, color: DZColors.placeholderColor),
                  ),
              ],
            ),
          ),
          CupertinoSwitch(
            value: value,
            activeColor: DZColors.mainColor,
            onChanged: onChanged,
          ),
        ],
      ),
    );
  }
}
